package com.kkshop.domain.security;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.kkshop.domain.Persistent;

@Entity
@Table(name = "users")
public class User implements Persistent<String> {

    @Id
    private String username;

    @Basic
    private String password;

    @Basic
    private int enabled;

    public User(String username, String password, int enabled) {
        this.username = username;
        this.password = password;
        this.enabled = enabled;
    }

    public User() {
    }
    
    public String getId() {
		return username;
	}

	public void setId(String id) {
		username = id;
	}

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getEnabled() {
        return enabled;
    }

    public void setEnabled(int enabled) {
        this.enabled = enabled;
    }

	public boolean equals(Object other) {
		if(!(other instanceof User)) {
			return false;
		}
		
		User that = (User) other;
		
		return new EqualsBuilder()
				.append(username, that.username)
				.append(password, that.password)
				.append(enabled, that.enabled).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder()
				.append(username)
				.append(password)
				.append(enabled).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this)
				.append("username", username)
				.append("password", password)
				.append("enabled", enabled).toString();
	}
}
